#!/bin/sh


TMP_FILE="Collatz.test"

COUNT=$(valgrind ./main.app < Collatz.in 2>&1 | grep "ERROR\|lost:" | awk ' { print $4 " " $7 } ' | grep -cv "0 0")

if [ "$COUNT" -ne "0" ]; then
	echo "Failed release valgrind test."
	exit 1
fi

./main.app < Collatz.in > $TMP_FILE
diff Collatz.out $TMP_FILE >/dev/null 2>&1
rm $TMP_FILE
if [ "$?" -ne "0" ]; then
	echo "Failed release Collatz.out acceptance test."
	exit 2
fi


COUNT=$(./main.test 2>&1 | grep Failures | awk ' { print $4 } ' | grep -cv "0")
if [ "$COUNT" -ne "0" ]; then
	echo "Failed test Collatz.out assertions test."
	exit 3
fi

COUNT=$(valgrind ./main.test 2>&1 | grep "ERROR\|lost:" | awk ' { print $4 " " $7 } ' | grep -cv "0 0")

if [ "$COUNT" -ne "0" ]; then
	echo "Failed test valgrind test."
	exit 4
fi

exit 0
